library(fpp2)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## ── Attaching packages ────────────────────────────────────────────── fpp2 2.5 ──
## ✔ ggplot2 3.5.2 ✔ fma 2.5
## ✔ forecast 8.24.0 ✔ expsmooth 2.3
##
library(TTR)
# Plot and Inference
# view informaion of data
h02
## Jan Feb Mar Apr May Jun Jul
## 1991 0.4297950
## 1992 0.6601190 0.3362200 0.3513480 0.3798080 0.3618010 0.4105340 0.4833887
## 1993 0.7515028 0.3875543 0.4272832 0.4138902 0.4288588 0.4701264 0.5092097
## 1994 0.8193253 0.4376698 0.5061213 0.4704912 0.5106963 0.5405138 0.5581189
## 1995 0.8031126 0.4752582 0.5525723 0.5271078 0.5612498 0.5889776 0.6231336
## 1996 0.9372759 0.5287616 0.5593399 0.5778717 0.6149274 0.5941888 0.7077584
## 1997 0.8468335 0.4638225 0.4852732 0.5280586 0.5623365 0.5885704 0.6694804
## 1998 0.8005444 0.4905572 0.5244080 0.5366495 0.5520905 0.6033656 0.6812454
## 1999 0.8930815 0.5126960 0.6529959 0.5739764 0.6392384 0.7038719 0.7706482
## 2000 0.9696557 0.5732915 0.6185068 0.6189957 0.6652092 0.7265201 0.8558649
## 2001 1.0438053 0.5106472 0.6725690 0.6484701 0.7041147 0.6994307 0.8519259
## 2002 1.1458676 0.5755844 0.6411646 0.6798621 0.7679384 0.7520959 0.9180636
## 2003 1.0781449 0.5782962 0.6433333 0.6633674 0.7505160 0.8007456 0.9163610
## 2004 1.1301252 0.6679887 0.7490143 0.7399860 0.7951286 0.8568028 1.0015932
## 2005 1.1706900 0.5976390 0.6525900 0.6705050 0.6952480 0.8422630 0.8743360
## 2006 1.2306910 0.5871350 0.7069590 0.6396410 0.8074050 0.7979700 0.8843120
## 2007 1.2233190 0.5977530 0.7043980 0.5617600 0.7452580 0.8379340 0.9541440
## 2008 1.2199410 0.7618220 0.6494350 0.8278870 0.8162550 0.7621370
## Aug Sep Oct Nov Dec
## 1991 0.4009060 0.4321590 0.4925430 0.5023690 0.6026520
## 1992 0.4754634 0.5347610 0.5686061 0.5952233 0.7712578
## 1993 0.5584430 0.6015141 0.6329471 0.6996054 0.9630805
## 1994 0.6728521 0.6858974 0.6896920 0.7413036 0.8133076
## 1995 0.7408372 0.7253718 0.8158030 0.8140095 0.9266531
## 1996 0.7195020 0.7443237 0.8048551 0.7885423 0.9710894
## 1997 0.6779937 0.7629955 0.7997237 0.7705219 0.9943893
## 1998 0.6780753 0.7948926 0.7846239 0.8130087 0.9777323
## 1999 0.8461859 0.8927289 0.8978999 0.9472807 1.0507073
## 2000 0.8659843 0.8252488 0.9554210 0.9385960 1.0130244
## 2001 0.9077052 0.8674445 1.0242928 1.1095902 1.0123132
## 2002 0.9243675 1.0131977 1.0269761 1.0067960 1.1027757
## 2003 0.9168868 1.0846589 1.1506482 1.0508382 1.2232345
## 2004 0.9948643 1.1344320 1.1810110 1.2160370 1.2572380
## 2005 1.0064970 1.0947360 1.0270430 1.1492320 1.1607120
## 2006 1.0496480 0.9957090 1.1682530 1.1080380 1.1200530
## 2007 1.0782195 1.1109816 1.1099791 1.1635343 1.1765890
## 2008
?h02
# data structure check
attributes(h02)
## $tsp
## [1] 1991.500 2008.417 12.000
##
## $class
## [1] "ts"
frequency(h02)
## [1] 12
start(h02)
## [1] 1991 7
end(h02)
## [1] 2008 6
plot(h02)

# The time series plot reveals a steadily increasing trend with clear seasonal cycles and random noise.
Acf(h02)

# The ACF plot of h02 shows slowly decaying correlations, suggesting the series is non-stationary with trend or seasonality, indicating that differencing or a trend-adjusted model would be appropriate before forecasting.
# Central Tendency
summary(h02)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.3362 0.5889 0.7471 0.7682 0.9376 1.2572
boxplot(h02)

# The summary statistics and box plot indicate that the time series is centered around a stable mean, shows moderate variation, and may contain occasional seasonal outliers. The distribution is roughly symmetric with a possible slight right skew, showing with the upward-trending, seasonal nature of the data.
# Naive
# Assumes future = last observed value. Forecast line is horizontal starting at the last point of data.
naive_forecast <- naive(h02,12)
plot(naive_forecast)

summary(naive_forecast)
##
## Forecast method: Naive method
##
## Model Information:
## Call: naive(y = h02, h = 12)
##
## Residual sd: 0.1558
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.001637153 0.1558455 0.09783678 -2.224008 14.68563 1.613981
## ACF1
## Training set -0.1028344
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2008 0.762137 0.56241290 0.9618611 0.45668535 1.067589
## Aug 2008 0.762137 0.47968447 1.0445895 0.33016313 1.194111
## Sep 2008 0.762137 0.41620471 1.1080693 0.23307922 1.291195
## Oct 2008 0.762137 0.36268880 1.1615852 0.15123370 1.373040
## Nov 2008 0.762137 0.31554034 1.2087337 0.07912634 1.445148
## Dec 2008 0.762137 0.27291487 1.2513591 0.01393631 1.510338
## Jan 2009 0.762137 0.23371670 1.2905573 -0.04601211 1.570286
## Feb 2009 0.762137 0.19723194 1.3270421 -0.10181074 1.626085
## Mar 2009 0.762137 0.16296470 1.3613093 -0.15421795 1.678492
## Apr 2009 0.762137 0.13055394 1.3937201 -0.20378593 1.728060
## May 2009 0.762137 0.09972710 1.4245469 -0.25093152 1.775206
## Jun 2009 0.762137 0.07027242 1.4540016 -0.29597856 1.820253
attributes(naive_forecast)
## $names
## [1] "method" "model" "lambda" "x" "fitted" "residuals"
## [7] "series" "mean" "level" "lower" "upper"
##
## $class
## [1] "forecast"
plot(naive_forecast$residuals)

hist(naive_forecast$residuals)

# fitted values vs residuals
plot(fitted(naive_forecast), residuals(naive_forecast),
main = "Fitted Values vs Residuals",
xlab = "Fitted Values", ylab = "Residuals")
abline(h = 0, col = "red")

# actual vs residuals
plot(h02, residuals(naive_forecast),
main = "Actual Values vs Residuals",
xlab = "Actual Values", ylab = "Residuals")
abline(h = 0, col = "red")

#ACF of Residuals
Acf(naive_forecast$residuals)

accuracy(naive_forecast)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.001637153 0.1558455 0.09783678 -2.224008 14.68563 1.613981
## ACF1
## Training set -0.1028344
# The Naive forecast provides a simple baseline with about 14.7% average error. It predicts the next year’s values will remain constant at approximately 0.762, but since it ignores trend and seasonality, it offers only moderate accuracy and should mainly serve as a comparison benchmark for more sophisticated forecasting methods.
# Moving Average
# Applies a 3-point,6-point, and 9-point rolling average to smooth short-term noise of existing data.
attributes(h02)
## $tsp
## [1] 1991.500 2008.417 12.000
##
## $class
## [1] "ts"
frequency(h02)
## [1] 12
start(h02)
## [1] 1991 7
end(h02)
## [1] 2008 6
plot(h02)

MA3 <- ma(h02,order=3)
plot(MA3)

MA6 <- ma(h02,order=6)
plot(MA6)

MA9 <- ma(h02,order=9)
plot(MA9)
lines(h02)
lines(MA3, col = "red", lwd = 2)
lines(MA6, col = "blue", lwd = 2)
lines(MA9, col = "green", lwd = 2)

# forecast for the next 12 month
MA3_forecast <- forecast(MA3, h = 12)
## Warning in ets(object, lambda = lambda, biasadj = biasadj,
## allow.multiplicative.trend = allow.multiplicative.trend, : Missing values
## encountered. Using longest contiguous portion of time series
MA6_forecast <- forecast(MA6, h = 12)
## Warning in ets(object, lambda = lambda, biasadj = biasadj,
## allow.multiplicative.trend = allow.multiplicative.trend, : Missing values
## encountered. Using longest contiguous portion of time series
MA9_forecast <- forecast(MA9, h = 12)
## Warning in ets(object, lambda = lambda, biasadj = biasadj,
## allow.multiplicative.trend = allow.multiplicative.trend, : Missing values
## encountered. Using longest contiguous portion of time series
summary(MA9_forecast)
##
## Forecast method: ETS(A,A,A)
##
## Model Information:
## ETS(A,A,A)
##
## Call:
## ets(y = object, lambda = lambda, biasadj = biasadj, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.9147
## beta = 0.0119
## gamma = 0.0847
##
## Initial states:
## l = 0.4097
## b = 0.0058
## s = 0.0556 0.0668 0.031 -0.0157 -0.0606 -0.0561
## -0.035 -0.0304 -0.017 -8e-04 0.0208 0.0415
##
## sigma: 0.0104
##
## AIC AICc BIC
## -739.1031 -735.6649 -683.3752
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.001543912 0.009939295 0.007847395 -0.206143 1.052432 0.1873755
## ACF1
## Training set 0.452078
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Mar 2008 0.9327369 0.9194451 0.9460287 0.9124088 0.9530649
## Apr 2008 0.9275186 0.9093983 0.9456390 0.8998060 0.9552313
## May 2008 0.9153197 0.8933212 0.9373182 0.8816759 0.9489635
## Jun 2008 0.9083792 0.8830122 0.9337462 0.8695837 0.9471747
## Jul 2008 0.9583123 0.9299036 0.9867209 0.9148650 1.0017596
## Aug 2008 1.0046246 0.9734047 1.0358445 0.9568779 1.0523713
## Sep 2008 1.0521988 1.0183399 1.0860576 1.0004161 1.1039814
## Oct 2008 1.0351577 0.9987939 1.0715215 0.9795440 1.0907714
## Nov 2008 1.0252280 0.9864665 1.0639894 0.9659475 1.0845085
## Dec 2008 1.0066163 0.9655453 1.0476873 0.9438036 1.0694290
## Jan 2009 0.9883288 0.9450215 1.0316361 0.9220960 1.0545617
## Feb 2009 0.9699680 0.9244863 1.0154496 0.9004098 1.0395262
accuracy(MA9_forecast)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.001543912 0.009939295 0.007847395 -0.206143 1.052432 0.1873755
## ACF1
## Training set 0.452078
# As the moving average order increases from 3 to 9, the plot becomes smoother and less noisy, but also lags behind the actual data, so it better for long-term trend identification but less effective for short-term forecasting.
# Simple Exponential Smoothing
# Only uses the level component without trend and seasonality. The plot shows the forecast is similar to the mean or naïve model, but slightly adjusted by alpha.
SSE_forecast <- ses(h02,h=12)
summary(SSE_forecast)
##
## Forecast method: Simple exponential smoothing
##
## Model Information:
## Simple exponential smoothing
##
## Call:
## ses(y = h02, h = 12)
##
## Smoothing parameters:
## alpha = 0.8822
##
## Initial states:
## l = 0.4266
##
## sigma: 0.1553
##
## AIC AICc BIC
## 329.0028 329.1228 338.9571
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.001899398 0.154527 0.09506631 -2.405843 14.22123 1.568278
## ACF1
## Training set 0.007057982
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2008 0.7684112 0.5693990 0.9674234 0.464048244 1.072774
## Aug 2008 0.7684112 0.5030178 1.0338046 0.362526982 1.174295
## Sep 2008 0.7684112 0.4501951 1.0866273 0.281741714 1.255081
## Oct 2008 0.7684112 0.4049703 1.1318521 0.212576352 1.324246
## Nov 2008 0.7684112 0.3647813 1.1720411 0.151112595 1.385710
## Dec 2008 0.7684112 0.3282466 1.2085758 0.095237554 1.441585
## Jan 2009 0.7684112 0.2945202 1.2423022 0.043657484 1.493165
## Feb 2009 0.7684112 0.2630396 1.2737828 -0.004487977 1.541310
## Mar 2009 0.7684112 0.2334082 1.3034143 -0.049805354 1.586628
## Apr 2009 0.7684112 0.2053339 1.3314885 -0.092741237 1.629564
## May 2009 0.7684112 0.1785944 1.3582280 -0.133635755 1.670458
## Jun 2009 0.7684112 0.1530157 1.3838067 -0.172755044 1.709577
# As the showing result, the smoothing parameter alpha is approximately 0.8822, meaning the model assigns 88% weight to the most recent observation and 12% to past forecasts, providing moderate smoothing. The initial level (l) is around 0.4266, which represents the model’s starting value of the smoothed series. The sigma value of about 0.1553 indicates that the residuals vary by roughly 0.16 units, suggesting reasonable model accuracy and stable forecast performance.
# residual
attributes(SSE_forecast)
## $names
## [1] "model" "mean" "level" "x" "upper" "lower"
## [7] "fitted" "method" "series" "residuals"
##
## $class
## [1] "forecast"
plot(SSE_forecast$residuals)

# The residual plot shows no clear trend or recurring pattern, suggesting the SES model has adequately captured the level of the series, and residuals behave like random noise.
hist(SSE_forecast$residuals)

# The histogram of residuals appears roughly symmetric and centered around zero, implying the forecast errors are evenly distributed and there is no systematic over or under forecasting.
# fitted values vs residuals
plot(fitted(SSE_forecast), residuals(SSE_forecast),
main = "Fitted Values vs Residuals",
xlab = "Fitted Values", ylab = "Residuals")
abline(h = 0, col = "red")

# The residuals appear randomly dispersed around zero without a distinct pattern, suggesting that the model errors are constant across fitted values.
# actual vs residuals
plot(h02, residuals(SSE_forecast),
main = "Actual Values vs Residuals",
xlab = "Actual Values", ylab = "Residuals")
abline(h = 0, col = "red")

# The residuals show no systematic relationship with actual values, implying forecast errors are independent of the size of the observations.
# ACF of Residuals
Acf(SSE_forecast$residuals)

# The ACF plot shows autocorrelation spikes within the confidence limits, indicating residuals are uncorrelated.
accuracy(SSE_forecast)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.001899398 0.154527 0.09506631 -2.405843 14.22123 1.568278
## ACF1
## Training set 0.007057982
# Forecast
SSE_forecast
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2008 0.7684112 0.5693990 0.9674234 0.464048244 1.072774
## Aug 2008 0.7684112 0.5030178 1.0338046 0.362526982 1.174295
## Sep 2008 0.7684112 0.4501951 1.0866273 0.281741714 1.255081
## Oct 2008 0.7684112 0.4049703 1.1318521 0.212576352 1.324246
## Nov 2008 0.7684112 0.3647813 1.1720411 0.151112595 1.385710
## Dec 2008 0.7684112 0.3282466 1.2085758 0.095237554 1.441585
## Jan 2009 0.7684112 0.2945202 1.2423022 0.043657484 1.493165
## Feb 2009 0.7684112 0.2630396 1.2737828 -0.004487977 1.541310
## Mar 2009 0.7684112 0.2334082 1.3034143 -0.049805354 1.586628
## Apr 2009 0.7684112 0.2053339 1.3314885 -0.092741237 1.629564
## May 2009 0.7684112 0.1785944 1.3582280 -0.133635755 1.670458
## Jun 2009 0.7684112 0.1530157 1.3838067 -0.172755044 1.709577
plot(SSE_forecast)

# The Simple Exponential Smoothing model (alpha = 0.8822, sigma = 0.1553) demonstrates moderate to good accuracy, with forecast errors averaging about 0.16 units. The model predicts that the time series will remain steady around 0.75 over the next year, as SES smooths recent data without adding a trend component. The residual diagnostics indicate randomness, and the widening confidence intervals reflect increasing uncertainty over time. Overall, this SES model performs well for short-term forecasts but may understate long-term trend or seasonal effects.
# Holt-Winters
# Exponential smoothing model with smooths level, trend, and seasonality.
HW <- HoltWinters(h02)
plot(HW)

HW_forecast <- forecast(HW,h=12)
plot(HW_forecast)

summary(HW_forecast)
##
## Forecast method: HoltWinters
##
## Model Information:
## Holt-Winters exponential smoothing with trend and additive seasonal component.
##
## Call:
## HoltWinters(x = h02)
##
## Smoothing parameters:
## alpha: 0.1859385
## beta : 0.03027679
## gamma: 0.5448286
##
## Coefficients:
## [,1]
## a 1.011607904
## b 0.001682796
## s1 -0.034366701
## s2 0.079625866
## s3 0.103401606
## s4 0.143474875
## s5 0.167622657
## s6 0.187190396
## s7 0.232205834
## s8 -0.310508911
## s9 -0.317757898
## s10 -0.274488158
## s11 -0.211075949
## s12 -0.196849130
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.005067435 0.05558297 0.04205395 -1.338585 5.522799 0.6937502
## ACF1
## Training set -0.04817681
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2008 0.9789240 0.9078027 1.0500452 0.8701534 1.0876946
## Aug 2008 1.0945994 1.0221849 1.1670139 0.9838509 1.2053478
## Sep 2008 1.1200579 1.0462977 1.1938181 1.0072515 1.2328643
## Oct 2008 1.1618140 1.0866565 1.2369715 1.0468705 1.2767574
## Nov 2008 1.1876445 1.1110387 1.2642504 1.0704860 1.3048030
## Dec 2008 1.2088951 1.1307907 1.2869994 1.0894448 1.3283453
## Jan 2009 1.2555933 1.1759411 1.3352455 1.1337758 1.3774108
## Feb 2009 0.7145614 0.6333128 0.7958100 0.5903023 0.8388204
## Mar 2009 0.7089952 0.6261025 0.7918878 0.5822218 0.8357685
## Apr 2009 0.7539477 0.6693643 0.8385312 0.6245885 0.8833069
## May 2009 0.8190427 0.7327226 0.9053628 0.6870275 0.9510580
## Jun 2009 0.8349523 0.7468505 0.9230541 0.7002123 0.9696924
#The trend smoothing parameter (beta = 0.0303) indicates a slow, stable trend update, while the seasonal smoothing parameter (gamma = 0.5448) shows moderately adaptive seasonality. The initial level (a = 1.0116) and trend (b = 0.00168) indicate a slightly increasing series, and the seasonal indices confirm strong recurring monthly patterns. The sigma = 0.0556 shows small residual variation, meaning the model’s forecasts are highly accurate. Overall, with a MAPE of about 5.5%, the Holt-Winters model effectively captures the underlying level, trend, and seasonality.
# residual
attributes(HW_forecast)
## $names
## [1] "method" "model" "level" "mean" "lower" "upper"
## [7] "x" "series" "fitted" "residuals"
##
## $class
## [1] "forecast"
plot(HW_forecast$residuals)

# The residuals fluctuate randomly around zero with no visible trend, indicating that the model has successfully captured the series’ level, trend, and seasonality.
hist(HW_forecast$residuals)

# The residuals form a roughly symmetric, bell-shaped curve centered near zero, which indicates that forecast errors are normally distributed without significant bias.
# fitted values vs residuals
plot(fitted(HW_forecast), residuals(HW_forecast),
main = "Fitted Values vs Residuals",
xlab = "Fitted Values", ylab = "Residuals")
abline(h = 0, col = "red")

# The scatter of residuals shows no particular direction or shape, suggesting that the model maintains constant error variance and captures the pattern well.
# actual vs residuals
plot(h02, residuals(HW_forecast),
main = "Actual Values vs Residuals",
xlab = "Actual Values", ylab = "Residuals")
abline(h = 0, col = "red")

# There is no systematic relationship between the actual observations and their residuals, meaning the forecasting errors do not depend on how large or small the data values are.
# ACF of Residuals
Acf(HW_forecast$residuals)

# The ACF of residuals shows no significant autocorrelation, confirming that the residuals behave like white noise.
accuracy(HW_forecast)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.005067435 0.05558297 0.04205395 -1.338585 5.522799 0.6937502
## ACF1
## Training set -0.04817681
# Forecast
HW_forecast
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2008 0.9789240 0.9078027 1.0500452 0.8701534 1.0876946
## Aug 2008 1.0945994 1.0221849 1.1670139 0.9838509 1.2053478
## Sep 2008 1.1200579 1.0462977 1.1938181 1.0072515 1.2328643
## Oct 2008 1.1618140 1.0866565 1.2369715 1.0468705 1.2767574
## Nov 2008 1.1876445 1.1110387 1.2642504 1.0704860 1.3048030
## Dec 2008 1.2088951 1.1307907 1.2869994 1.0894448 1.3283453
## Jan 2009 1.2555933 1.1759411 1.3352455 1.1337758 1.3774108
## Feb 2009 0.7145614 0.6333128 0.7958100 0.5903023 0.8388204
## Mar 2009 0.7089952 0.6261025 0.7918878 0.5822218 0.8357685
## Apr 2009 0.7539477 0.6693643 0.8385312 0.6245885 0.8833069
## May 2009 0.8190427 0.7327226 0.9053628 0.6870275 0.9510580
## Jun 2009 0.8349523 0.7468505 0.9230541 0.7002123 0.9696924
plot(HW_forecast)

# The Holt-Winters model showa its low RMSE (0.0556) and MAPE (5.5 %), indicating that the model’s predicted values are very close to the actual data. It forecasts the time-series values to remain around 0.83 after one year, continuing a slight upward trend with consistent seasonal fluctuations. Overall, this technique effectively captures both the long-term trend and seasonal patterns of the data, producing reliable short-term forecasts with minimal residual error and no significant autocorrelation.
# Decomposition
decomp <- stl(h02,s.window ="periodic")
plot(decomp)

attributes(decomp)
## $names
## [1] "time.series" "weights" "call" "win" "deg"
## [6] "jump" "inner" "outer"
##
## $class
## [1] "stl"
# The decomposition clearly shows repeating cycles each year, with peaks and troughs occurring at roughly the same months.That means the series is seasonal, exhibiting a strong annual pattern.
# Since the amplitude of seasonal fluctuations increases as the overall level of the series rises, the relationship between trend and seasonality is proportional, so the decomposition is multiplicative
seasonal <- decomp$time.series[, "seasonal"]
# Compute average seasonal value per month
seasonal_indices <- tapply(seasonal, cycle(h02), mean, na.rm = TRUE)
round(seasonal_indices, 3)
## 1 2 3 4 5 6 7 8 9 10 11
## 0.215 -0.237 -0.180 -0.185 -0.134 -0.102 -0.007 0.038 0.081 0.128 0.142
## 12
## 0.241
# The series shows its peak in December and its lowest level in February.
# The time series reaches its highest level in December, likely due to year-end effects such as increased consumer spending, production ramp-ups before holidays, or seasonal demand surges. The lowest values occur in February, so there is reduced activity following the holiday season or winter slowdowns.
# seasonally adjusted time series
tmp <- seasadj(decomp)
plot(h02)
lines(seasadj(decomp), col="Red")

f_decomp <- forecast(decomp)
plot(f_decomp)

accuracy(f_decomp)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.005199088 0.05867155 0.04511275 0.5595693 6.334258 0.7442102
## ACF1
## Training set -0.06776442
# The seasonal pattern shows noticeable swings between high and low months. Once adjusted for seasonality, the adjusted series becomes much smoother, confirming that seasonality contributes significantly to the short term variation in the time series.
# Accuracy Summary
accuracy(naive_forecast)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.001637153 0.1558455 0.09783678 -2.224008 14.68563 1.613981
## ACF1
## Training set -0.1028344
accuracy(MA3_forecast)
## ME RMSE MAE MPE MAPE MASE
## Training set -7.209564e-05 0.02291878 0.01745602 -0.02048244 2.309078 0.3587604
## ACF1
## Training set 0.233545
accuracy(MA6_forecast)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.002373772 0.01395908 0.01141697 0.3896638 1.534046 0.2596974
## ACF1
## Training set 0.6703257
accuracy(MA9_forecast)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.001543912 0.009939295 0.007847395 -0.206143 1.052432 0.1873755
## ACF1
## Training set 0.452078
accuracy(SSE_forecast)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.001899398 0.154527 0.09506631 -2.405843 14.22123 1.568278
## ACF1
## Training set 0.007057982
accuracy(HW_forecast)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.005067435 0.05558297 0.04205395 -1.338585 5.522799 0.6937502
## ACF1
## Training set -0.04817681
acc_Naive <- accuracy(naive_forecast)
acc_MA3 <- accuracy(MA3_forecast)
acc_MA6 <- accuracy(MA6_forecast)
acc_MA9 <- accuracy(MA9_forecast)
acc_SES <- accuracy(SSE_forecast)
acc_HW <- accuracy(HW_forecast)
accuracy_table <- rbind("Naive" = acc_Naive, "MA3" = acc_MA3, "MA6" = acc_MA6, "MA9" = acc_MA9, "SES" = acc_SES, "HW" = acc_HW)
accuracy_table <- rbind(
"Naive" = acc_Naive["Training set", ],
"MA3" = acc_MA3["Training set", ],
"MA6" = acc_MA6["Training set", ],
"MA9" = acc_MA9["Training set", ],
"SES" = acc_SES["Training set", ],
"HW" = acc_HW["Training set", ]
)
round(accuracy_table, 4)
## ME RMSE MAE MPE MAPE MASE ACF1
## Naive 0.0016 0.1558 0.0978 -2.2240 14.6856 1.6140 -0.1028
## MA3 -0.0001 0.0229 0.0175 -0.0205 2.3091 0.3588 0.2335
## MA6 0.0024 0.0140 0.0114 0.3897 1.5340 0.2597 0.6703
## MA9 -0.0015 0.0099 0.0078 -0.2061 1.0524 0.1874 0.4521
## SES 0.0019 0.1545 0.0951 -2.4058 14.2212 1.5683 0.0071
## HW -0.0051 0.0556 0.0421 -1.3386 5.5228 0.6938 -0.0482
# Naive method uses the most recent observation as the forecast for all future periods. It provides a baseline to compare against more advanced methods.
# Moving Average (MA3, MA6, MA9) averages the last 3, 6, or 9 months to smooth short-term fluctuations and highlight longer-term trends. It is Good for stable series without strong trend or seasonality.
# Simple Exponential Smoothing assigns exponentially decreasing weights to past observations, controlled by smoothing factor alpha. Useful for short-term forecasts where the level changes slowly but there’s no trend or seasonality.
# Holt–Winters extends exponential smoothing by adding trend (beta) and seasonal (gamma) components. It is best for time series with clear trend and seasonal patterns; adapts to both level and seasonal shifts.
# Among all methods tested, the MA(9) moving average achieves the best overall accuracy with the lowest RMSE, MAE, and MAPE, showing that a longer smoothing window captures the general trend effectively and minimizes short-term noise. The Naïve and SES methods perform the worst, both showing higher forecast errors and larger percentage deviations.
# Conclusion
# The time series shows a clear seasonal pattern repeating each year with moderate fluctuations. Peaks tend to occur in December and troughs around February, consistent with cyclical demand or production patterns. Over the full period, the trend appears gradually increasing, suggesting a steady upward movement in the level of the series.
# The value of the time series is expected to increase moderately over the next year and continue rising over the next two years, following the same cyclical pattern.
# Based on the accuracy results, the MA(9) method ranks as the most accurate overall, producing the lowest RMSE, MAE, and MAPE values. It effectively smooths the data and captures the underlying pattern with minimal error. The MA(6) method follows closely, offering similar performance but slightly higher variability. The Holt–Winters model ranks next—it captures both trend and seasonality well but shows slightly larger residuals. The MA(3) method performs moderately, while SES and Naive methods show the weakest accuracy, as they fail to model seasonality adequately and primarily serve as baseline comparisons.
# Overall, the time series exhibits a steady seasonal pattern with a mild upward trend. The MA(9) model provides the best forecasting performance historically, while Holt-Winters is the most conceptually robust for ongoing seasonal forecasting. Forecasts indicate that values will likely rise modestly over the next one to two years, maintaining consistent cyclical variation without significant volatility.